package com.neuedu.projectedu.common;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result<T> {
    private Result() {
    }

    private static String SUCCESS_CODE = "0000";
    private static String ERROR_CODE = "1111";
    // 错误代码
    private String code;
    // 数据
    private T data;
    // 消息描述
    private String msg = "ok";

    public static <T> Result success(T t) {
        return new Result<>(SUCCESS_CODE, t, "ok");
    }

    public static Result success(String msg) {
        return new Result<>(SUCCESS_CODE, null, msg);
    }

    public static Result success() {
        return new Result<>(SUCCESS_CODE, null, "ok");
    }

    public static Result fail(String msg) {
        return new Result<>(ERROR_CODE, null, msg);
    }
    public static <T> Result fail(String code,T t,String msg) {
        return new Result<>(code, t, msg);
    }
    public static Result fail() {
        return new Result<>(ERROR_CODE, null, "fail");
    }
}
